

<%@ page import="com.jeff.Flight" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'flight.label', default: 'Flight')}" />
        <title><g:message code="default.create.label" args="[entityName]" /></title>
        
        <g:javascript library="jquery" plugin="jquery"/> <!-- with out 'plugin="jquery"' it failed to load jq lib .js files in current version-->
        <script type="text/javascript">
			function getAirline(airlineField) {
				var baseUrl = "${createLink(controller:'airline', action:'getJson')}";
				var input = $('#' + airlineField);
				var url = baseUrl + "?code=" + input.val();
				var out = $('#' + airlineField + "Label");
				var hidden = $('#' + airlineField + "_id");
				//alert([url,out.text(),hidden.val()]);
				jQuery.get(
					url,
					function(data) {
						out.html(input.val() + ' - ' + data.name);
						(data.id == null)? hidden.value = -1 : hidden.value = data.id;
						//alert(hidden.value);
					}
				);				
			}
        </script>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.create.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${flightInstance}">
            <div class="errors">
                <g:renderErrors bean="${flightInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form action="save" >
                <div class="dialog">
                    <table>
                        <tbody>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="no"><g:message code="flight.no.label" default="No" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: flightInstance, field: 'no', 'errors')}">
                                    <g:textField name="no" value="${flightInstance?.no}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="airline"><g:message code="flight.airline.label" default="Airline" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: flightInstance, field: 'airline', 'errors')}">
<%--                                    <g:select name="airline.id" from="${com.jeff.Airline.list()}" optionKey="id" value="${flightInstance?.airline?.id}"  />--%>
									<div id="flightAirlineLabel">[Type an Airline Code]</div>
									<g:hiddenField name="flightAirline.id" value="-1" id="flightAirline_id"/>
									<g:textField name="flightAirline" id="flightAirline"/><input type="button" onclick="getAirline('flightAirline')" value="Find">
                                </td>
                            </tr>
                        
                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
                </div>
            </g:form>
        </div>
    </body>
</html>
